package com.wang.vagus.exception;

import com.wang.vagus.base.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理自定义的业务异常
     */
    @ExceptionHandler(value = Exception.class)
    public Result exceptionHandler(Exception e){

        if (e instanceof BaseException){
            log.error("发生业务异常！原因是：{}",e.getMessage());
            return Result.error((BaseException) e);
        }else {
            log.error("发生未知异常！原因是：{}",e.getMessage());
            e.printStackTrace();
            return Result.error(e);

        }

    }
}
